package ip.ejb.entity;
/***********************************************************************
 * Module:  CategoryBean.java
 * Author:  mojsilo
 * Purpose: Defines the Class CategoryBean
 ***********************************************************************/

import ip.ejb.sequence.SequenceSessionLocal;
import ip.ejb.sequence.SequenceSessionLocalHome;

import java.sql.Date;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityContext;
import javax.naming.InitialContext;

/**
 * @ejb.bean 
 * 	cmp-version="2.x"
 *  name="Category"
 *  type="CMP"
 *  jndi-name="ip/ejb/entity/Category"
 *  local-jndi-name="ip/ejb/entity/CategoryLocal"
 *  reentrant="false"
 *  
 * @ejb.finder
 *   signature="java.util.Collection findAll()"
 *   query="SELECT OBJECT(a) FROM Category a"
 *   method-intf="LocalHome"
 *  
 * @ejb.persistence
 * 	table-name="category"
 * 
 * @ejb.transaction
 * 	type="Required"
 * 
 * @jboss.table-name
 * 	table-name="category"
 * 
 * @jboss.create-table
 * 	create="true"
 * 
 * @jboss.remove-table
 * 	remove="false"
 */
public abstract class CategoryBean implements javax.ejb.EntityBean
{
	private EntityContext ejbContext = null;
	private SequenceSessionLocal sequenceSession = null;

	/**
	 * @ejb.create-method view-type="both"
	 */
	public CategoryPK ejbCreate(String name) throws CreateException {

		setCategoryId(sequenceSession.getNextValue("Category"));
		setName(name);

		return null;
	}   

	public void ejbPostCreate(String name){}
	
	public void setEntityContext(EntityContext ctx) throws javax.ejb.EJBException
	{
		SequenceSessionLocalHome home = null;
		Object obj = null;
		this.ejbContext = ctx;
		try {
			obj = (new InitialContext()).lookup("ejb/util/SequenceSessionLocal");
			home = (SequenceSessionLocalHome) obj;
			sequenceSession = home.create();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void unsetEntityContext() throws javax.ejb.EJBException
	{
		   this.ejbContext = null;
		   try {
			   sequenceSession.remove();
		   } catch (Exception ex) {
			   ex.printStackTrace();
		   }
	}

	/**
	 * @ejb.persistence column-name="category_id"
	 * @ejb.interface-method view-type="both"
	 * @ejb.pk-field
	 * @jboss.jdbc-type type="BIGINT"
	 * @jboss.sql-type  type="BIGINT(20)"
	 */
	public abstract long getCategoryId();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setCategoryId(long categoryId);

	/**
	 * @ejb.persistence column-name="name"
	 * @ejb.interface-method view-type="both"
	 * @jboss.jdbc-type type="VARCHAR"
	 * @jboss.sql-type  type="VARCHAR(30)"
	 */
	public abstract String getName();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setName(String name);

	
	/**
	 * @ejb.interface-method view-type="local"
	 * @ejb.relation
	 *   name="Movie-Category"
	 *   role-name="Category-contains-Movie"
	 *   target-ejb="Movie"
	 */
	public abstract Collection getMovie();

	/**
	 * @ejb.interface-method view-type="local"
	 */
	public abstract void setMovie(Collection movies);
	
	public void ejbActivate() throws javax.ejb.EJBException{}
	public void ejbLoad() throws javax.ejb.EJBException{}
	public void ejbPassivate() throws javax.ejb.EJBException{}
	public void ejbRemove() throws javax.ejb.RemoveException, javax.ejb.EJBException{}
	public void ejbStore() throws javax.ejb.EJBException{}

}